package com.goldgov.jsondoc;

import java.io.File;
import java.io.FileOutputStream;

import com.alibaba.fastjson.JSON;
import com.goldgov.jsondoc.doc.GenerateWordByIText;
import com.goldgov.jsondoc.revsoler.JsonInfo;
import com.goldgov.jsondoc.revsoler.JsonRevsoler;
import com.goldgov.jsondoc.revsoler.impl.UrlJsonRevsoler;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws Exception
    {
    	execute("http://127.0.0.1:8080/json/url.json", "C:\\Users\\leemonk\\Desktop\\test.doc");
    }
    
    public static void execute(String url,String filePath)throws Exception {
    	JsonRevsoler jsonRevsoler = new UrlJsonRevsoler();
    	String jsonFromUrl = jsonRevsoler.getJsonFromUrl(url);
    	JsonInfo parseObject = JSON.parseObject(jsonFromUrl, JsonInfo.class);
    	
    	File file = new File(filePath);
    	if(!file.exists()) {
    		file.createNewFile();
    	}
    	GenerateWordByIText.generateDocument(new FileOutputStream(file), parseObject);
    }
}
